package oop.factor;

import oop.analyzer.AnalyzerBuilder;
import oop.analyzer.method.FilterMethod;
import oop.analyzer.method.SortMethod;
import oop.data.DataStore;
import oop.data.RowData;

import java.io.File;
import java.util.Map;
import java.util.regex.Pattern;

public class Factor {
    public static void main(String[] args) {
        DataStore<RowData> datas = new DataStore<RowData>();
        Reader Reader;

		String path = System.getProperty("user.dir") + "/OOP-Experiment-2/data";
		//从文件夹中取出文件，交给Reader处理
		File dirFile = new File(path);
		File files[] = dirFile.listFiles();//遍历文件夹
		for(File file : files){
			String pattern = ".*\\.csv";
			boolean isMatch = Pattern.matches(pattern, file.getName()); //判断文件名是否符合要求
			if(isMatch){
		        Reader = new Reader(file.getAbsolutePath());
		        datas.appendDatas(Reader.getDatas());
			}
		}


        //初始化处理器对象,设定处理链,并执行分析返回分析结果.
		Map<String, DataStore<RowData>>  result = AnalyzerBuilder.createAnalyzerLinks().append(new FilterMethod()).append(new SortMethod()).analy(datas);
		new Outer(result);

        
    }
}
